#ifndef RECTANGLEFINDER_H
#define RECTANGLEFINDER_H

#include "DataStructures.h"

#include <vector>

class RectangleFinder
{
public:
    RectangleFinder( double angleTol , double closeTol );
    ~RectangleFinder();

    void process( const std::vector<LineSegmentF>& lines );

    const std::vector<LineSegRect>& getRectangles();

private:

    void segmentByAxis( const std::vector<LineSegmentF>& lines );
    void checkSaveRect( const LineSegmentF& side0 ,
                        const LineSegmentF& side1 ,
                        const std::vector<LineSegmentF>& perpendicular );
    void addRectangle( LineSegmentF &l , LineSegmentF &r, LineSegmentF &t, LineSegmentF &b );

    // how close to being parallel or perpendicular do the lines need to be
    double angleTol;
    // how close two points need to be to be considered close
    double closeTol;

    // lines that are approximately horizontal
    std::vector<LineSegmentF> vert;
    // lines that are approximately verticle
    std::vector<LineSegmentF> horiz;

    // list of all the rectangles found defined using the line segments that
    // define their edges
    std::vector<LineSegRect> foundRect;

};

#endif // RECTANGLEFINDER_H
